package cn.vin.demo;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Joiner;
import com.google.gson.Gson;
import org.apache.lucene.util.RamUsageEstimator;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.time.LocalDate;
import java.time.Month;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo3 {

    public static void main(String[] args) throws Exception {
        LocalDate localDate = LocalDate.of(2019, Month.SEPTEMBER,4);
        System.out.println(localDate);
    }

    static class People implements Comparable<Demo.People> {
        Integer id;
        Integer age;

        public People(Integer id, Integer age) {
            this.id = id;
            this.age = age;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Demo.People people = (Demo.People) o;
            return id.equals(people.id);
        }

        @Override
        public int hashCode() {
            return Objects.hash(id);
        }

        @Override
        public int compareTo(Demo.People o) {
            return this.age > o.getAge() ? 1 : -1;
        }

        @Override
        public String toString() {
            return "People{" +
                    "id=" + id +
                    ", age=" + age +
                    '}';
        }
    }

    class Peoples {
        private HashMap<Integer, Integer> map = new HashMap<>();

        public Peoples(People... people) {
            ArrayList<People> peoples = new ArrayList<>(Arrays.asList(people));
            peoples.forEach(p -> map.put(p.getId(), p.getAge()));
        }

        public List<People> getDisSortPeople() {
            ArrayList<People> list = new ArrayList<>();
            Stream<Map.Entry<Integer, Integer>> st = map.entrySet().stream();
            st.sorted(Comparator.comparing(e -> e.getValue())).forEach(e ->
                    list.add(new People(e.getKey(), e.getValue())));
            return list;
        }
    }
}
